<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<?php 
	$ci = &get_instance();
	$USER = $ci->user_entity->init('id',$ESCORT->getUserId());
	$geoArray = explode('#', $ESCORT->getGeolocation());
	$lat = count($geoArray)==2 ? $geoArray[0] :'0';
	$lng = count($geoArray)==2 ? $geoArray[1] :'0';
?>

<?php if( $ESCORT->getPublicPhone() == 1 ): ?>
	<div class="escort-infor-item-wrapper">
		<div class="escort-infor-item-left">
			<span><?php echo language_translate('contact_info_phone');?></span>
		</div>
		<div class="escort-infor-item-right">
			<span>
				<img src="<?php echo createImageText($ESCORT->getEscortPhone(),'phone_'.$ESCORT->getId());?>" />
			</span>
		</div>
		<div class="clear"></div>
	</div>
<?php endif; ?>

<?php if( $ESCORT->getPublicEmail() == 1 ): ?>
	<div class="escort-infor-item-wrapper">
		<div class="escort-infor-item-left">
			<span><?php echo language_translate('contact_info_email');?></span>
		</div>
		<div class="escort-infor-item-right">
			<span>
				<img src="<?php echo createImageText($ESCORT->getEscortEmail(),'email_'.$ESCORT->getId());?>" />
			</span>
		</div>
		<div class="clear"></div>
	</div>
<?php endif; ?>

<?php if( $ESCORT->getPublicAddress() == 1 ): ?>
	<div class="escort-infor-item-wrapper">
		<div class="escort-infor-item-left">
			<span><?php echo language_translate('contact_info_address');?></span>
		</div>
		<div class="escort-infor-item-right">
			<span>
				<?php echo $ESCORT->getEscortAddress();?> 
			</span>
		</div>
		<div class="clear"></div>
	</div>	
<?php endif; ?>


<div class="escort-infor-item-wrapper">
	<?php if($ESCORT->getPublicGeolocation()):?>
		<div id="map_canvas" style="width:350px;margin-top:20px;"></div> 
		<div class="clear"></div>
	<?php endif; ?>	
</div>


<?php if($ESCORT->getReceiveMessage()):?>
	<div class="escort-infor-item-wrapper">
		<div class="escort-infor-item-left">
			<span><?php echo language_translate('contact_zone_message_to_escort');?></span>
		</div>
	<form action="<?php echo site_url('home/submit_visitor_send_message');?>" name="submit_visitor_send_message" id="submit_visitor_send_message" method="post" enctype="multipart/form-data" >	
		<div class="escort-infor-item-right" style="margin-bottom:20px;">
			<label><?php echo language_translate('contact_zone_your_name');?></label>
			<div class="clear"></div>
			<input type="text" maxlength="45" id="visitor_name" name="visitor_name" />
			
			<div class="clear"></div>
			<label><?php echo language_translate('contact_zone_your_email');?></label>
			<div class="clear"></div>
			<input type="text" maxlength="45" id="visitor_email" name="visitor_email" />
			
			<div class="clear"></div>
			<label><?php echo language_translate('contact_zone_your_mobile_phone');?></label>
			<div class="clear"></div>
			<input type="text" maxlength="25" id="visitor_phone" name="visitor_phone" />
			
			<div class="clear"></div>
			<label><?php echo language_translate('contact_zone_your_message');?></label>
			<div class="clear"></div>
			<span>
				<textarea style="width:90%;height:100px;margin-top:10px;" id="message_to_escort" class="message_to_escort" name="message_to_escort"></textarea>
			</span>
			
			<div class="clear"></div>
			<label><?php echo language_translate('contact_zone_enter_captcha');?></label>
			<div class="clear"></div>
			<?php echo newCaptcha();?>
			<div class="clear"></div>
			<input type="text" maxlength="25" id="captcha" name="captcha" style="margin-bottom:10px;margin-top:5px;"/>
			
			<input type="hidden" value="<?php echo $ESCORT->getUserId();?>" name="user_id" />
			
			<div class="select-box">
				<input type="submit" class="save-button" value="Send" /> 
				<?php echo loader_image("id='contact_zone_loader_image' class='hidden'");?>
			</div>
			
			<div id="error-message" style="color:red;"></div>
			<div>
				<div id="update-message" style="margin-top:10px;"><?php echo language_translate('contact_zone_successfully_message');?></div>
				<div class="clear"></div>
			</div>
		</div>
	</form>	
		<div class="clear"></div>
	</div>
<?php endif; ?>



<script type="text/javascript">
	var displayMap = '<?php echo $ESCORT->getShowAddressOnMap();?>';
	var address = '<?php echo $USER->getAddress();?>';
	var isGMAPShow = '<?php echo ($ESCORT->getPublicGeolocation() == 1) ? $ESCORT->getPublicGeolocation() :0;?>';
	
	$(document).ready(function() {	
		$('#contact-info').height(650);
		$('#map_canvas').height(350);
		
		var options = { 
			beforeSubmit:  validateB4SubmitContact,  
			success:       processAfterRespondingContact  
		};	
		$('#submit_visitor_send_message').ajaxForm(options); 
		
		if(isGMAPShow == '1'){
			showMap(<?php echo $lat ;?>,<?php echo $lng ;?>);
		}
		
		$( "#accordion" ).bind( "accordionchange", function(event, ui) {
		   if(isGMAPShow == '1'){
				showMap(<?php echo $lat ;?>,<?php echo $lng ;?>);
			}
		});
	});	
	
//	google.setOnLoadCallback(function() {
//		
//	});
	
	function validateB4SubmitContact(formData, jqForm, options){
		$('#contact_zone_loader_image').show();
		$('#error-message').html('');
		$('#contact-info').height('auto');
		return true;
	}
	
	function processAfterRespondingContact(responseText, statusText, xhr, $form) {
		$('#contact_zone_loader_image').hide();	
		if(responseText == 'ok'){
			updatedShow();
		}else{
			$('#error-message').html(responseText).show();
			$('#contact-info').height('auto');
		}
	}
	
	function showMap(lat , lng){
		geocoder = new google.maps.Geocoder();
		var latlng = new google.maps.LatLng(lat,lng);
		var myOptions = {
		  zoom: 14,
		  center: latlng,
		  mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
		marker = new google.maps.Marker({
		  position: latlng,
		  map: map
		});
		
		var contentString = '<div id="overlay-window-info">'+address+'</div>';
		var infowindow = new google.maps.InfoWindow({
			content: contentString
		});

		if(displayMap){
			google.maps.event.addListener(marker, 'click', function() {
				infowindow.open(map,marker);
			});
		}		
	}
</script>






